const merge = require('webpack-merge')
const getWebpackConfig = require('../build/webpack.common')

module.exports = function (config) {
  // webpack 处理
  let webpackConfig = getWebpackConfig({
    rootPath: __dirname,
    include: __dirname
  })
  // webpackConfig.plugins.shift()
  delete webpackConfig.entry
  delete webpackConfig.output
  webpackConfig = merge(webpackConfig, {
    mode: 'development',
    devtool: 'inline-source-map'
  })

  config.set({
    frameworks: ['jasmine'],
    files: ['./index.js'],
    preprocessors: {
      './index.js': ['webpack', 'sourcemap']
    },
    webpack: webpackConfig,
    webpackMiddleware: {
      stats: 'errors-only'
      // noInfo: true
    },
    reporters: ['spec'],
    browsers: ['Chrome'],
    // browsers: ['ChromeHeadless'],
    plugins: [
      'karma-jasmine',
      'karma-webpack',
      'karma-spec-reporter',
      'karma-sourcemap-loader',
      'karma-chrome-launcher'
    ]
  })
}
